package com.linkhub.oms.admin.modules.user.bankstatement.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import cn.dev33.satoken.annotation.SaMode;
import com.linkhub.oms.admin.modules.satoken.session.LhSessionContext;
import com.linkhub.oms.admin.modules.user.bankstatement.domain.param.UserBankStatementQueryParam;
import com.linkhub.oms.admin.modules.user.bankstatement.domain.vo.UserBankStatementExcelVO;
import com.linkhub.oms.admin.modules.user.bankstatement.domain.vo.UserBankStatementVO;
import com.linkhub.oms.admin.modules.user.bankstatement.service.IUserBankStatementService;
import com.linkhub.oms.common.constant.RoleConstant;
import com.linkhub.oms.common.response.DataResponse;
import com.linkhub.oms.common.response.PageDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

/**
 * 用户账户模块
 *
 * @author Frank
 */
@Slf4j
@RestController
@Api(tags = {"用户账户_银行流水模块接口"})
@RequestMapping("/user/account/bank/statement")
@SaCheckLogin
public class UserBankStatementController {
    @Resource
    private IUserBankStatementService userBankStatementService;

    @GetMapping()
    @ApiOperation(value = "银行流水列表")
    @SaCheckRole(value = {RoleConstant.EMPLOYEE, RoleConstant.FINANCE}, mode = SaMode.OR)
    public DataResponse<PageDTO<UserBankStatementVO>> getBankStatementPage(@Validated UserBankStatementQueryParam queryParam) {
        queryParam.setUserId(LhSessionContext.getUserId());
        queryParam.setEmployeeRoleFlag(LhSessionContext.isEmployeeRole());
        return DataResponse.success(userBankStatementService.getBankStatementPage(queryParam));
    }

    @PostMapping("/excel")
    @ApiOperation(value = "导入银行流水")
    @SaCheckRole(value = {RoleConstant.FINANCE})
    public DataResponse<UserBankStatementExcelVO> importExcel(@RequestParam("file") MultipartFile file) {
        return DataResponse.success(userBankStatementService.importExcel(LhSessionContext.getUserId(), file));
    }

}
